# Maintainer: Gustavo Alvarez <sl1pkn07@gmail.com>
# Contributor: Mikhail Vorozhtsov <mikhail.vorozhtsov@gmail.com>
# Contributor: Nagisa <simonas@kazlauskas.me>
# Contributor: Misc <andreas.reis@gmail.com>
# Contributor: Jeagoss <jgoliver@jeago.com>

#########################
## -- Build options -- ##
#########################

_use_clang=1          # Use clang compiler. Results in faster build and smaller chromium.
_use_system_clang=1   # Use system clang compiler instead of build bundled.
_use_pax=0            # If set 1, change PaX permisions in executables NOTE: only use if use PaX environment (IN TEST)
_use_hidpi=0          # Set 1 if use a HiDPI panel, like Apple Retina
_use_widevine=0       # Support Widevine from Google

##############################################
## -- Package and components information -- ##
##############################################
pkgname=chromium-dev
pkgver=42.0.2305.3
pkgrel=1
pkgdesc='The open-source project behind Google Chrome (Dev Channel)'
arch=('i686' 'x86_64')
url="http://www.chromium.org/"
license=('BSD')
depends=('desktop-file-utils' 'hicolor-icon-theme' 'gtk2' 'icu' 'libexif' 'libsecret' 'libwebp' 'libxslt' 'libxss' 'minizip'
         'nss' 'pciutils' 're2' 'snappy' 'speech-dispatcher' 'speex' 'ttf-font' 'xdg-utils') # 'libvpx' 'opus' 'jsoncpp' 'protobuf'  'libsrtp' 'libevent'
makedepends=('elfutils' 'gperf' 'ninja' 'perl-json' 'python2-beautifulsoup3' 'python2-jinja' 'python2-simplejson' 'python2-ply' 'subversion' 'yasm' 'git' 'ccache') #
makedepends_x86_64=('lib32-gcc-libs' 'lib32-zlib')
optdepends=('chromium-pepper-flash-dev: PPAPI Flash Player (Dev Channel)'
            'kdebase-kdialog: Needed for file dialogs in KDE4'
            'kdeutils-kwalletmanager: For storing passwords in KWallet in KDE4'
            'kdialog-frameworks-git: Needed for file dialogs in KF5'
            'kwalletmanager-git: Needed for storing passwords in KWallet in KF5'
            'libappindicator-gtk2: Needed for show systray icon in the panel in plasma-next (KF5)')
[ "${CARCH}" = "x86_64" ] && warning "To build in x86_64 systems, need to have activated the repository [multilib]. If not , the build will fail"
install=chromium-dev.install
backup=('etc/chromium-dev/default')
source=("https://commondatastorage.googleapis.com/chromium-browser-official/chromium-${pkgver}.tar.xz"
        'chromium-dev.desktop'
        'chromium-dev.sh'
        'chromium-dev.default'
        'chromium-dev.xml'
        # Patch form Gentoo
        'http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/www-client/chromium/files/chromium-system-jinja-r7.patch'
        'http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/www-client/chromium/files/chromium-libsecret-r0.patch'
        # Misc Patches
        'chromium-widevine.patch'
        # Patch from crbug (chromium bugtracker)
        )
sha1sums=('8ebf11bfdb1bcf1415ff170c155d8603b5420d21'
          'aa07e8539935d9f472c30db30a4c88549ba7cc2b'
          'e543ecbdfb382e1221a530190508d93b4764a074'
          '6ad810bf4931ce42791cb06c3f1ecaafa376467b'
          '055fd99aedcb20343128854c3b00f7a731b6df20'
          'c24d14029714d2295f3220a7173a5a7362f578a2'
          'f08045a04aab50ea2c537f09a11ba50a84ab45f2'
          'b88be7c488ef4db26a96acc6e90450e184fdb221')
sha512sums=('adacf02727ff940e264e022c025dd31d1e9e9bba8575bd518abdc8b3b834926975d394bd856cd3a59d95fc0f6fb4e170087146f24cd8fa8e336272c504063be5'
            '5b1721cc273642565bc617d732c41abdca5245c42608cd9bceb60d39cbdb3e22af183916feaef52f6b2eb748dfc8f260632e99dd298b12362e48fd8fb13e9214'
            'cbb15f0bc1d93aabc805c3a7bc98848d96b0157965bb517cba94a92fc98b3ce85511156a1289d3bfdc5d99dad42073b79e689d6af320625f5a2ff6f50459ddf3'
            '83c247adc419b0ed7c055bb7d7cb59d4b13510af96ce6d655e236221398c7b86355308b2a86233d0d561cd51d1fb79cb32435f0e9ce12a578b4b804e88a14d54'
            '8eccbf694cb26a530b35a3750f308f489f6fbcc6dbb74064117e0117d5e67a95e0f5a713c76ff8c86149930e3965aa8186307afb773b8da6c301fda7201db3fa'
            '689cee917bd8a81edb4e640d551eca8bbbca9fa7c8d0afbca513cd911880773e7bfa0e3d558ca770afb418c6e0b42c28edb08b4792de900df1fb0b58afba22ee'
            '455e690c1eb885315a1a78cef35510d7fd75155400ba86b5de021641c21671f49fbbb72bf1d1b0c80b2c9c6723058a9ce8b5a66ebac0f3ba06b91600807af411'
            'da5948c28b0446879502eb0b1490bf06d1ffc8d93fe4bb769f50835b357af7691d474083262b5b5d89ee46ab295e9cab475a8e81833c45f9cfdcecf024f250c4')

options=('!strip')

################################################
## -- Don't touch anything below this line -- ##
################################################

# Google API keys (see http://www.chromium.org/developers/how-tos/api-keys)
# NOTE: These are for Arch Linux use ONLY. For your own distribution, please
# get your own set of keys. Feel free to contact foutrelis@archlinux.org for
# more information.
#_google_api_key="AIzaSyDwr302FpOSkGRpLlUpPThNTDPbXcIn_FM"
#_google_default_client_id="413772536636.apps.googleusercontent.com"
#_google_default_client_secret="0ZChLK6AxeA3Isu96MkwqDR4"

# 32 or 64 bits?
[ "${CARCH}" = "i686" ] && _target_arch="ia32" && _arch="x86_32" && _build_ffmpeg_args=" --disable-asm"
[ "${CARCH}" = "x86_64" ] && _target_arch="x64" && _arch="x86_64" && _build_ffmpeg_args=""

# If use PaX environment, need 'paxctl'
[ "${_use_pax}" = "1" ] && makedepends+=('paxctl')

# Use system clang?
[ "${_use_clang}" = "1" ] && makedepends+=('cmake')
[ "${_use_system_clang}" = "1" ] && makedepends+=('clang')

# Use Widevide?
[ "${_use_widevine}" = "1" ] && makedepends+=('chromium-widevine-dev')

# Are we in Gnome?
_use_gnome=0
if [ -f /usr/lib/libgnome-keyring.so ]; then
  depends+=('libgnome-keyring' 'gnome-keyring')
  _use_gnome=1
fi

# Use Pulseaudio?
_use_pulseaudio=0
if [ -x /usr/lib/libpulse.so ]; then
  depends+=('libpulse')
  _use_pulseaudio=1
fi


# Set necesary bundled components to build (the rest is removed in prepare() function (remove_bundled_libraries.py script))
_necesary=(
  'base/third_party/dmg_fp'
  'base/third_party/dynamic_annotations'
  'base/third_party/icu'
  'base/third_party/nspr'
  'base/third_party/superfasthash'
  'base/third_party/symbolize'
  'base/third_party/valgrind'
  'base/third_party/xdg_mime'
  'base/third_party/xdg_user_dirs'
  'breakpad/src/third_party/curl'
  'chrome/third_party/mozilla_security_manager'
  'courgette/third_party'
  'crypto/third_party/nss'
  'native_client/src/third_party/dlmalloc'
  'net/third_party/mozilla_security_manager'
  'net/third_party/nss'
  'third_party/WebKit'
  'third_party/analytics'
  'third_party/angle'
  'third_party/angle/src/third_party/compiler'
  'third_party/brotli'
  'third_party/cacheinvalidation'
  'third_party/cld_2'
  'third_party/cros_system_api'
  'third_party/cython/python_flags.py'
  'third_party/dom_distiller_js'
  'third_party/dom_distiller_js/package/proto_gen/third_party/dom_distiller_js'
  'third_party/ffmpeg'
  'third_party/fips181'
  'third_party/flot'
  'third_party/flac' #manually added
  'third_party/google_input_tools'
  'third_party/google_input_tools/third_party/closure_library'
  'third_party/google_input_tools/third_party/closure_library/third_party/closure'
  'third_party/hunspell'
  'third_party/iccjpeg'
  'third_party/jsoncpp'
  'third_party/jstemplate'
  'third_party/khronos'
  'third_party/leveldatabase'
  'third_party/libaddressinput'
  'third_party/libevent'
  'third_party/libjingle'
  'third_party/libphonenumber'
  'third_party/libsrtp'
  'third_party/libudev'
  'third_party/libusb'
  'third_party/libvpx'
  'third_party/libvpx/source/libvpx/third_party/x86inc'
  'third_party/libxml/chromium'
  'third_party/libXNVCtrl'
  'third_party/libyuv'
  'third_party/lss'
  'third_party/lzma_sdk'
  'third_party/mesa'
  'third_party/mojo'
  'third_party/modp_b64'
  'third_party/mt19937ar'
  'third_party/npapi'
  'third_party/openmax_dl'
  'third_party/opus'
  'third_party/ots'
  'third_party/pdfium'
  'third_party/pdfium/third_party/base'
  'third_party/pdfium/third_party/bigint'
  'third_party/pdfium/third_party/freetype'
  'third_party/polymer'
  'third_party/protobuf'
  'third_party/qcms'
  'third_party/readability'
  'third_party/sfntly'
  'third_party/skia'
  'third_party/smhasher'
  'third_party/sqlite'
  'third_party/tcmalloc'
  'third_party/tlslite'
  'third_party/trace-viewer'
  'third_party/trace-viewer/third_party/d3'
  'third_party/trace-viewer/third_party/components/polymer'
  'third_party/trace-viewer/third_party/gl-matrix'
  'third_party/trace-viewer/third_party/jszip'
  'third_party/trace-viewer/third_party/tvcm'
  'third_party/trace-viewer/third_party/tvcm/third_party/beautifulsoup/polymer_soup.py'
  'third_party/undoview'
  'third_party/usrsctp'
  'third_party/webdriver'
  'third_party/webrtc'
  'third_party/widevine'
  'third_party/x86inc'
  'third_party/zlib/google'
  'url/third_party/mozilla'
  'v8/src/third_party/fdlibm'
  'v8/src/third_party/kernel'
  'v8/src/third_party/valgrind'
)

# Set build flags
# NOTE
# -Denable_sql_database=0                    | http://crbug.com/22208
# -Dlogging_like_official_build=1            | Save space by removing DLOG and DCHECK messages (about 6% reduction).
# -Dlinux_use_gold_flags=0                   | Never use bundled gold binary. Disable gold linker flags for now.
# -Dusb_ids_path=/usr/share/hwdata/usb.ids   | Use the file at run time instead of effectively compiling it in.
_flags=(
  "-Dclang=${_use_clang}"
  '-Ddisable_glibc=1'
  '-Ddisable_fatal_linker_warnings=1'
  '-Denable_sql_database=0'
  "-Denable_hidpi=${_use_hidpi}"
  '-Dffmpeg_branding=Chrome'
  '-Duse_official_google_api_keys=0' #git
#  "-Dgoogle_api_key=${_google_api_key}"
#  "-Dgoogle_default_client_id=${_google_default_client_id}"
#  "-Dgoogle_default_client_secret=${_google_default_client_secret}"
  '-Dicu_use_data_file_flag=0'
#  '-Dlibspeechd_h_prefix=speech-dispatcher/'
  "-Dlinux_link_gnome_keyring=${_use_gnome}"
  "-Dlinux_link_gsettings=${_use_gnome}"
  '-Dlinux_link_libpci=1'
#  '-Dlinux_link_libspeechd=1' #orig
  '-Dlinux_link_libspeechd=0'
  '-Dlinux_strip_binary=1'
  '-Dlinux_use_bundled_binutils=0'
  '-Dlinux_use_bundled_gold=0'
  '-Dlinux_use_gold_flags=0'
  '-Dlogging_like_official_build=1'
  '-Dno_strict_aliasing=1'
  '-Dproprietary_codecs=1'
  '-Dremove_webcore_debug_symbols=1'
  "-Dtarget_arch=${_target_arch}"
  '-Dusb_ids_path=/usr/share/hwdata/usb.ids'
  '-Duse_gconf=0'
  "-Duse_gnome_keyring=${_use_gnome}"
  "-Duse_pulseaudio=${_use_pulseaudio}"
  -Dlinux_link_pulseaudio="${_use_pulseaudio}"  #git
  '-Dwerror=' #prevent warnings from failing build https://code.google.com/p/chromium/wiki/LinuxBuildInstructions#Sample_configurations

#extra stuff from git:
  '-Dpython_ver=2.7' #git
  -Ddisable_nacl=1
  -Ddisable_pnacl=1
  -Ddcheck_always_on=0

  -Denable_mpeg2ts_stream_parser=0 #already 0
  -Ddisable_glibcxx_debug=1
  -Dv8_enable_i18n_support=0
  -Ddisable_nacl_untrusted=1
  -Djava_bridge=0
  -Ddebug_devtools=0
#  -Dandroid_lint=0
  -Demma_coverage=0 # already 0
#  -Duse_official_google_api_keys=0 #already above
  -Dvideo_hole=0
  -Denable_hangout_services_extension=0
  -Denable_wifi_bootstrapping=0
  -Denable_service_discovery=0
  -Denable_managed_users=0
  -Denable_plugin_installation=0
  -Duse_xi2_mt=0 # multitouch stuff
  -Ddisable_ftp_support=0
  -Ddisable_file_support=0
  -Denable_task_manager=1 # already 1
  -Denable_background=0
  -Denable_prod_wallet_service=0
  -Denable_autofill_dialog=0 # already 0
  -Denable_themes=0
  -Denable_session_service=0 # if something fails, enable this
  -Denable_webrtc=0
  -Denable_spellcheck=1
  -Denable_printing=0
  -Denable_google_now=0
  -Denable_extensions=1 # already 1 by default
  -Denable_pre_sync_backup=0 # already 0 by default
  -Denable_one_click_signin=0 # already 0 by default
  -Dnotifications=0
  -Denable_web_speech=0
  -Dsafe_browsing=0
  -Dconfiguration_policy=1 #set to 1 if compilation errors
  -Dremoting=0
  -Dcomponent=shared_library
  -Dtracing_like_official_build=1
  -Dfastbuild=2
  -Ddont_embed_build_metadata=1

#won't work here and not in this form either:  "-Dflapper_version_h_file=\"${srcdir}/flapper_version.h\""
)

if [ "${_use_clang}" = "1" ]; then
  if [ "${_use_system_clang}" = "1" ]; then
    _flags+=('-Dclang_use_chrome_plugins=0')
  elif [ "${_use_system_clang}" = "0" ]; then
    _flags+=('-Dclang_use_chrome_plugins=1')
  fi
fi

# Set the bundled/external components
# TODO
# -Duse_system_hunspell=1    | Upstream changes needed
# -Duse_system_jsoncpp=1     | Need newer version (>0.7.0)
# -Duse_system_libsrtp=1     | https://bugs.gentoo.org/show_bug.cgi?id=459932
# -Duse_system_libvpx=1      | http://crbug.com/347823
# -Duse_system_libusb=1      | http://crbug.com/266149
# -Duse_system_opus=1        | https://code.google.com/p/webrtc/issues/detail?id=3077
# -Duse_system_sqlite=1      | http://crbug.com/22208
# -Duse_system_ssl=1         | http://crbug.com/58087
# -Duse_system_openssl=1     | Use if use BoringSSL instead of SSL
# NOTE
# -Duse_system_libevent=0    | Need older version (<2.x.x)
# -Duse_system_protobuf=0    | https://bugs.gentoo.org/show_bug.cgi?id=525560
# -Duse_system_v8=0          | Possible broken in API/ABI if use a differen version
# -Duse_system_libxnvctrl=0  | Because not exist in Arch
_use_system=(
  '-Duse_system_expat=1'
  '-Duse_system_ffmpeg=0'
#  '-Duse_system_flac=1' #orig  #what's the point if this is hardcoded #include "third_party/flac/include/FLAC/stream_encoder.h" in ./content/browser/speech/audio_encoder.cc  - manually FIXED: supposedly!
  '-Duse_system_flac=0'
  '-Duse_system_fontconfig=1'
  '-Duse_system_harfbuzz=1'
  '-Duse_system_icu=1'
#  '-Duse_system_icu=0' #git
  '-Duse_system_jsoncpp=0'
#  '-Duse_system_libevent=0'
  '-Duse_system_libevent=1'
  '-Duse_system_libexif=1'
  '-Duse_system_libjpeg=1'
  '-Duse_system_libpng=1'
  '-Duse_system_libusb=0'
  '-Duse_system_libvpx=0'
  '-Duse_system_libwebp=1'
  '-Duse_system_libxml=1'
  '-Duse_system_libxnvctrl=0'
  '-Duse_system_libxslt=1'
  '-Duse_system_minizip=1'
  '-Duse_system_nspr=1'
  '-Duse_system_openssl=0'
  '-Duse_system_opus=0'
  '-Duse_system_protobuf=0'
  '-Duse_system_re2=1'
  '-Duse_system_snappy=1'
  '-Duse_system_speex=1'  #well this needs a patch ./content/browser/speech/audio_encoder.cc has this hardcoded: #include "third_party/speex/include/speex/speex.h" 
#  '-Duse_system_speex=0' #added manually
  '-Duse_system_sqlite=0'
  '-Duse_system_ssl=0'
  '-Duse_system_v8=0'
  '-Duse_system_yasm=1'
  '-Duse_system_xdg_utils=1'
  '-Duse_system_zlib=1'
  '-Duse_system_bzip2=1' #git
)

################################################

prepare() {

  # Set Python2 path
  mkdir -p python-path
  ln -s /usr/bin/python2 "${srcdir}/python-path/python" || echo whatever
  export PATH="${srcdir}/python-path:$PATH"

  cd "chromium-${pkgver}"

  msg2 "Fix to save configuration in ~/.config/chromium-dev"
  sed -e "s|'filename': 'chromium-browser'|'filename': 'chromium-dev'|" \
      -e "s|'confdir': 'chromium'|'confdir': 'chromium-dev'|" \
      -i chrome/chrome_exe.gypi
  sed -e 's|config_dir.Append("chromium")|config_dir.Append("chromium-dev")|' \
      -e 's|config_dir.Append("chrome-frame")|config_dir.Append("chrome-frame-dev")|' \
      -i chrome/common/chrome_paths_linux.cc

  # Support widevide from 'chromium-widevine-dev'
  if [ "${_use_widevine}" = "1" ]; then
    msg2 "Add Widevine Support"
    _widevine_version="$(< "/usr/lib/chromium-dev/widevine.version")"
    sed -e "s|@WIDEVINE_VERSION@|${_widevine_version}|" ../chromium-widevine.patch > "../chromium-widevine-${_widevine_version}.patch"
    patch -p1 -i "../chromium-widevine-${_widevine_version}.patch"
    mkdir -p "third_party/widevine/cdm/linux/${_target_arch}"
    cp /usr/lib/chromium-dev/libwidevinecdm.so third_party/widevine/cdm/widevine_cdm_*.h "third_party/widevine/cdm/linux/${_target_arch}/"
  fi

  msg2 "Patching the sources"
  # Patch sources from Gentoo
  patch -p0 -i ../chromium-system-jinja-r7.patch
  patch -p1 -i ../chromium-libsecret-r0.patch

  # Misc Patches:

  # Patch from crbug (chromium bugtracker)

  # Make it possible to remove third_party/adobe
  echo > "${srcdir}/flapper_version.h"
  #_flags+=("-Dflapper_version_h_file=${srcdir}/flapper_version.h") #already added above

  msg2 "Removing unnecessary components to save space"
  # Remove most bundled libraries. Some are still needed.
  build/linux/unbundle/remove_bundled_libraries.py ${_necesary[@]} --do-remove

  msg2 "Make sure use Python 2"
  find . -type f -exec sed -r -e 's|/usr/bin/python$|&2|g' -i {} +

#  msg2 "Setup NaCl/PNaCl SDK: Download and install NaCl/PNaCl toolchains"
#  build/download_nacl_toolchains.py --packages nacl_x86_newlib,pnacl_newlib,pnacl_translator sync

  msg2 "fix message center when notifications are disabled"
  sed -e "s|#if !defined(OS_ANDROID) && !defined(OS_IOS)||" \
      -e "s|#error This file should only be used in Android or iOS builds.||" \
      -e "s|#endif||" \
      -i "ui/message_center/dummy_message_center.cc"

}

build() {
  export PATH="${srcdir}/python-path:$PATH"
  _flags+=("-Dflapper_version_h_file=${srcdir}/flapper_version.h") #already added above

  cd "chromium-${pkgver}"

  #TODO: fix this if needed
#  sed -e "s|['enable_web_speech==0 and OS==\"android\"', {|['enable_web_speech==0', {|" \
#      -i content/content_browser.gypi

  # CFLAGS are passed through -Drelease_extra_cflags=
  export -n CFLAGS CXXFLAGS

  # Use system/bundled clang?
  if [ "${_use_clang}" = "1" ]; then
    if [ "${_use_system_clang}" = "1" ]; then
      msg2 "Setup system clang"
#      export CC="clang"
#      export CXX="clang++"
      export CC="ccache clang -Qunused-arguments"
      export CXX="ccache clang++ -Qunused-arguments"
      #export CCACHE_CPP2=yes
  #might need that ^ 
  # ^ http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html?showComment=1390921308307#c2753775068550152695
      export CXXFLAGS="${CXXFLAGS} -Wno-unknown-warning-option"
    elif [ "${_use_system_clang}" = "0" ]; then
      msg2 "Setup and build bundled Clang"
      tools/clang/scripts/update.sh --force-local-build --without-android
    fi
  elif [ "${_use_clang}" = "0" ]; then
    msg2 " Setup system GCC"
    # Silence "typedef 'x' locally defined but not used" warnings
    CFLAGS+=' -Wno-unused-local-typedefs'
    #FIXME: do I need export again here?
  fi
  msg2 "CC=$CC"
  msg2 "CXX=$CXX"

  # Changing bundle libraries to system ones
  build/linux/unbundle/replace_gyp_files.py ${_use_system[@]}

#  #something didn't change still: NOPE this isn't working: undefined reference
#  sed -e "s|third_party/flac|/usr|" \
#      -e "s|third_party/speex|/usr|" \
#      -i content/browser/speech/audio_encoder.cc
#only speex:
  sed -e "s|third_party/speex|/usr|" \
      -i content/browser/speech/audio_encoder.cc


  # Re-configure bundled ffmpeg
  msg2 "Configuring and build the bundled FFmpeg"
  pushd third_party/ffmpeg > /dev/null
  _CPPFLAGS="${CPPFLAGS}"
  export CPPFLAGS="${CPPFLAGS/-D_FORTIFY_SOURCE=2/} -D_FORTIFY_SOURCE=0"
  if [ "${_use_clang}" = "1" ] ; then
    if [ "${_use_system_clang}" = "1" ] ; then
      _build_ffmpeg_args+=" --cc=clang --cxx=clang++"
    elif [ "${_use_system_clang}" = "0" ] ; then
      _bundled_clang_path="${srcdir}/chromium-${pkgver}/third_party/llvm-build/Release+Asserts/bin"
      _build_ffmpeg_args+=" --cc=${_bundled_clang_path}/clang --cxx=${_bundled_clang_path}/clang++"
    fi
  fi
  chromium/scripts/build_ffmpeg.py linux ${_target_arch} --branding=Chrome -- ${_build_ffmpeg_args}
  chromium/scripts/copy_config.sh
  chromium/scripts/generate_gyp.py
  export CPPFLAGS="${_CPPFLAGS}"
  popd > /dev/null

  third_party/libaddressinput/chromium/tools/update-strings.py

  msg2 "Starting building Chromium..."
  build/gyp_chromium --depth=. -Drelease_extra_cflags="$CFLAGS" ${_flags[@]} ${_use_system[@]}

  if [ "${_use_pax}" = "1" ]; then
    # Build mksnapshot and pax-mark it.
    ninja -C out/Release -v "mksnapshot"
    paxctl -cm "out/Release/mksnapshot"
  fi

  ninja -j1 -C out/Release -v chrome chrome_sandbox #chromedriver

  if [ "${_use_pax}" = "1" ]; then
    # Pax-mark again
    paxctl -cm out/Release/chrome
  fi
}

package() {
  install -Dm644 chromium-dev.default "${pkgdir}/etc/chromium-dev/default"
  install -Dm755 chromium-dev.sh "${pkgdir}/usr/bin/chromium-dev"
  install -Dm644 chromium-dev.desktop "${pkgdir}/usr/share/applications/chromium-dev.desktop"
  install -Dm644 "chromium-${pkgver}/LICENSE" "${pkgdir}/usr/share/licenses/chromium-dev/LICENSE"

  cd "chromium-${pkgver}/out/Release"
  install -Dm755 chrome "${pkgdir}/usr/lib/chromium-dev/chromium-dev"
  install -Dm4755 -o root -g root chrome_sandbox "${pkgdir}/usr/lib/chromium-dev/chrome-sandbox"
#  install -Dm755 chromedriver "${pkgdir}/usr/lib/chromium-dev/chromedriver"
#  ln -s /usr/lib/chromium-dev/chromedriver "${pkgdir}/usr/bin/chromedriver-dev"

  for i in chrome_100_percent.pak content_resources.pak keyboard_resources.pak resources.pak; do
    install -Dm644 "${i}" "${pkgdir}/usr/lib/chromium-dev/${i}"
  done

  install -Dm755 libffmpegsumo.so "${pkgdir}/usr/lib/chromium-dev/libffmpegsumo.so"
#  TODO: check if this line is needed: probably not because: - libpdf now integrated into a binary src: comments from https://aur.archlinux.org/packages/chromium-dev/
#  install -Dm755 libpdf.so "${pkgdir}/usr/lib/chromium-dev/libpdf.so"  #git has this
  [ "${_use_widevine}" = "1" ] && install -Dm755 libwidevinecdmadapter.so "${pkgdir}/usr/lib/chromium-dev/libwidevinecdmadapter.so"


  find locales -type f -name "*.pak" -exec install -Dm644 '{}' "${pkgdir}/usr/lib/chromium-dev/{}" \;
#  TODO: check if this line is needed:
#  find lib -type f -name "*.so" -exec install -Dm644 '{}' "${pkgdir}/usr/lib/chromium-dev/{}" \; #git has this

  install -Dm644 chrome.1 "${pkgdir}/usr/share/man/man1/chromium-dev.1"

  for _size in 16 22 24 32 48 128 256; do
    case "${_size}" in
      16|32) _branding="${srcdir}/chromium-${pkgver}/chrome/app/theme/default_100_percent/chromium" ;;
      *) _branding="${srcdir}/chromium-${pkgver}/chrome/app/theme/chromium" ;;
    esac
    install -Dm644 "${_branding}/product_logo_${_size}.png" "${pkgdir}/usr/share/icons/hicolor/${_size}x${_size}/apps/chromium-dev.png"
  done

#  install -Dm755 nacl_helper "${pkgdir}/usr/lib/chromium-dev/nacl_helper"
#  install -Dm755 nacl_helper_bootstrap "${pkgdir}/usr/lib/chromium-dev/nacl_helper_bootstrap"
#  install -Dm755 nacl_helper_nonsfi "${pkgdir}/usr/lib/chromium-dev/nacl_helper_nonsfi"
#  install -Dm755 "nacl_irt_${_arch}.nexe" "${pkgdir}/usr/lib/chromium-dev/nacl_irt_${_arch}.nexe"

#  install -Dm644 natives_blob.bin "${pkgdir}/usr/lib/chromium-dev/natives_blob.bin"
#  install -Dm644 snapshot_blob.bin "${pkgdir}/usr/lib/chromium-dev/snapshot_blob.bin"

  [ "${_use_gnome}" = "1" ] && install -Dm644 "${srcdir}/chromium-dev.xml" "${pkgdir}/usr/share/gnome-control-center/default-apps/chromium-dev.xml"

  # Manually strip binaries so that 'nacl_irt_*.nexe' is left intact
  strip $STRIP_BINARIES "${pkgdir}/usr/lib/chromium-dev/"{chromium-dev,chrome-sandbox,chromedriver,nacl_helper{,_bootstrap,_nonsfi}}
  strip $STRIP_SHARED "${pkgdir}/usr/lib/chromium-dev/libffmpegsumo.so"
}
